package com.example.person_web.common;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Date;

public class DateUtil implements Serializable {
    /**
     * 获取当前时间
     * @return
     */
   public static Date getCurrentDate() {
       // 获取当前时间
       LocalDateTime localDateTime = LocalDateTime.now();
       // 将 LocalDateTime 转换为 Date 类型
       Date currentDate = Date.from(localDateTime.atZone(ZoneId.systemDefault()).toInstant());
       return currentDate;
   }
   public static String getCurrentDateStr() {
       LocalDateTime now = LocalDateTime.now();

       // 定义格式器
       DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");

       // 格式化时间
       String formattedDateTime = now.format(formatter);
       return formattedDateTime;
   }
}
